//sort()排序函数的实现
#include <iostream>
#include <vector>
using namespace std;
//自定义排序方法
template<typename T>
bool fun(const T &right,const T &left){
    return right<left;
}
//仿函数
template<typename T>
class person{
public:
    bool operator()(const T &right,const T &left){
        return right<left;
    }
};
//排序算法--冒泡排序
template<typename T1,typename T2>
void msort(T1 first,T1 last,T2 pfun){
    while(true){
        bool bswap=false;//本轮遍历是否交换过元素
        for(auto it=first;;){
            auto left=it;
            it++;
            auto right=it;
            if(right==last)break;
            if(pfun(*right,*left)==true){
                auto tmp=*right;
                *right=*left;
                *left=tmp;
                bswap=true;
            }
        }
        if(bswap==false)break;
    }
}
template<typename T>
void print(T t){
    for(auto val:t){
        cout<<val<<" ";
    }
}
int main()
{
    vector<int> a {1,2,3,4,5,6,7,8,9};
    msort(a.begin(),a.end(),person<int>());
    print(a);
    return 0;
}